#!/usr/bin/python
# -*-coding: UTF-8 -*-
"""
# Time: 2021/11/14 22:05
# @Author: 修养
# @Project_name: PROJECT_NAME
"""
import json

# 1、
lists = ['张飞', '赵云']
lists.insert(2, '刘备')
lists.append('关羽')
del lists[0]
print(lists)
lists.pop()
lists[0] = '诸葛亮'
print('lists = ', lists, len(lists))

# 2、使用列表生成器打印100以内所有回文数
lists = [i for i in range(100)]
for num in lists:
    if num < 10:
        print(num, end=' ')
    elif num // 10 == num % 10:
        print(num, end=' ')
print()
# 3、list对象按age从大到小排序
alist = [{'name': 'a', 'age': '20'}, {'name': 'b', 'age': '23'}, {'name': 'c', 'age': '32'}]
sorted(alist, key=lambda x: x['age'], reverse=True)
print(alist)

# 4、将字符串处理成字典
sts_s = "k1:1|k2:2|k3:3|k4:4"
dicts = {}
list_s = sts_s.split('|')
print(list_s)
for x in list_s:
    k, v = x.split(':')
    dicts[k] = v
print(dicts)

d = {k:int(v) for t in sts_s.split("|") for k, v in (t.split(":"), )}

# 解法二、
dicts = {k: v for k, v in map(lambda x: x.split(':'), sts_s.split("|"))}
print(dicts)

